package org.example.shop.storage.controller;

import org.example.shop.entity.Storage;
import org.example.shop.storage.service.StorageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RefreshScope
public class StorageController {

    @Resource
    private StorageService storageService;

    @Value("${shop.storage.name:未知}")
    private String name;

    @Value("${redis.addr:none}")
    private String redis;

    @GetMapping("storage")
    public ResponseEntity<String> findName() {
        return ResponseEntity.ok(name+redis);
    }

    @PostMapping("storage")
    public ResponseEntity<Storage> save(@RequestBody Storage storage) {
        return ResponseEntity.ok(storageService.save(storage));
    }
}
